;; core/real.scm - (c) rohan drape, 2004-2005

;; Real valued (inexact) division and multiplication.

(define-syntax /. (syntax-rules () ((_ v ...) (exact->inexact (/ v ...)))))
(define-syntax *. (syntax-rules () ((_ v ...) (exact->inexact (* v ...)))))

;; Division variant that returns 0.0 instead an error on divide by
;; zero.

(define (/.* a b) (if (zero? b) 0.0 (/. a b)))

;; Real valued modulo calculation.

(define (modulo. n m) (let* ((d (/ n m)) (f (floor d)) (r (- d f))) (* r m)))

;; Real valued quotient and remainder calculation.

(define (quotient. a b) (floorE (/ a b)))
(define (remainder. a b) (- a (* (quotient. a b) b)))

;; Returns the lowest <real> multiple of `n' that is greater than `i'.

(define (next-multiple-of. i n) (* (+ (quotient. i n) 1) n))

;; Returns true iff n is an integer and is even.

(define (even?. n) (and (integer? n) (even? n)))

;; Variant that coerces n and e to exact values.

(define (rationalizeE n e) (rationalize (inexact->exact n) (inexact->exact e)))
